import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:pornhub_app/assets/assets.dart';
import 'package:pornhub_app/components/community_cell/community_cell.dart';
import 'package:pornhub_app/components/image_view.dart';
import 'package:pornhub_app/components/no_more/no_data.dart';
import 'package:pornhub_app/components/no_more/no_more.dart';
import 'package:pornhub_app/components/text_view.dart';
import 'package:pornhub_app/generate/app_image_path.dart';
import 'package:pornhub_app/model/community/community_model.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/utils/extension.dart';

import 'user_home_page_controller.dart';

class UserHomePage extends GetView<UserHomePageController> {
  const UserHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: _bodyView(),
    );
  }

  _bodyView() {
    return EasyRefresh(
      controller: controller.refreshController,
      refreshOnStart: false,
      onRefresh: () => controller.getHttpData(isRefresh: true),
      onLoad: () => controller.getUserDynamicLists(isRefresh: false),
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Obx(() => ImageView(
                  src: "${controller.userInfo.value.logo}",
                  width: 90.w,
                  height: 90.w,
                  fit: BoxFit.cover,
                  borderRadius: BorderRadius.circular(45.w),
                  defaultPlace: Assets.avatarplaceholer,
                )),
            8.verticalSpace,
            Obx(() => TextView(
                  text: "${controller.userInfo.value.nickName}",
                  fontSize: 18.w,
                  color: COLOR.white,
                )),
            6.verticalSpace,
            Obx(() => Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    TextView(
                      text: "${controller.userInfo.value.ua ?? 0} 关注",
                      fontSize: 14.w,
                      color: COLOR.color_9C9AA9,
                    ),
                    10.horizontalSpace,
                    TextView(
                      text: "${controller.userInfo.value.bu ?? 0} 粉丝",
                      fontSize: 14.w,
                      color: COLOR.color_9C9AA9,
                    ),
                  ],
                )),
            8.verticalSpace,
            Obx(() => controller.userService.user.userId == controller.userId
                ? const SizedBox.shrink()
                : ImageView(
                    src: controller.userInfo.value.attention == true
                        ? AppImagePath.mine_user_home_attention
                        : AppImagePath.mine_user_home_attention_add,
                    height: 25.w,
                    fit: BoxFit.fitHeight,
                  ).onOpaqueTap(() {
                    controller.attentionUser();
                  })),
            15.verticalSpace,
            PagedListView.separated(
              pagingController: controller.pagingControllers,
              padding: EdgeInsets.only(top: 8.w),
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              builderDelegate: PagedChildBuilderDelegate<CommunityModel>(
                firstPageProgressIndicatorBuilder: (context) =>
                    const SizedBox.shrink(),
                newPageProgressIndicatorBuilder: (context) =>
                    const SizedBox.shrink(),
                noMoreItemsIndicatorBuilder: (context) => const NoMore(),
                noItemsFoundIndicatorBuilder: (context) => const NoData(),
                itemBuilder: (context, item, index) =>
                    CommunityCell(model: item),
              ),
              separatorBuilder: (context, index) => Container(
                  height: 5.w, color: COLOR.white.withValues(alpha: 0.3)),
            ),
          ],
        ),
      ),
    );
  }

}
